package com.inxedu.os.edu.controller.mobil.service;

import com.alibaba.fastjson.JSON;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.exceptions.ClientException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Map;

@Service
public class SmsService {

    static final Logger LOGGER = LoggerFactory.getLogger(SendUtil.class);

    @Autowired
    private com.inxedu.os.edu.controller.mobil.service.SendUtil sendUtils;

    public CommonResponse send(String phone,String code) throws ClientException {
        CommonResponse response = sendUtils.send(phone,code);
        if (response != null && response.getHttpStatus() == 200){
            String data = response.getData();
            Map map = JSON.parseObject(data, Map.class);
            LOGGER.info("短信发送状态:{}" + phone + "=====" + code + "=====" + map.get("Message"));
        }

        if(response != null){
            //以下为Api的测试代码，不做理会即可
            boolean success = response.getHttpResponse().isSuccess();  //true
            int status = response.getHttpResponse().getStatus(); //200
            int httpStatus = response.getHttpStatus(); //200
        }

        return response;
    }
}